﻿using System.Data.Common;
using System.Data.Entity;
using Abp.Zero.EntityFramework;
using MyCompanyName.AbpZeroTemplate.Authorization.Roles;
using MyCompanyName.AbpZeroTemplate.Authorization.Users;
using MyCompanyName.AbpZeroTemplate.MultiTenancy;
using MyCompanyName.AbpZeroTemplate.Storage;

namespace MyCompanyName.AbpZeroTemplate.EntityFramework
{
    public class AbpZeroTemplateDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
        public virtual IDbSet<Daybooks.Daybook> Daybook { get; set; }
        public virtual IDbSet<Daybooks.DaybookItem> DaybookItem { get; set; }
        public virtual IDbSet<Gantt.Task> Tasks { get; set; }
        public virtual IDbSet<Gantt.Resource> Resources { get; set; }
        public virtual IDbSet<Gantt.Assignment> Assignments { get; set; }
        public virtual IDbSet<Gantt.Attachment> Attachments { get; set; }
        public virtual IDbSet<Gantt.Calendar> Calendars { get; set; }
        public virtual IDbSet<Gantt.CalendarDay> CalendarDays { get; set; }
        public virtual IDbSet<Gantt.Dependency> Dependencies { get; set; }
        public virtual IDbSet<Gantt.Option> Options { get; set; }
        public virtual IDbSet<Gantt.Schedule> Schedules { get; set; }
        public virtual IDbSet<Gantt.TaskSegment> TaskSegments { get; set; }
        public virtual IDbSet<Prm.Project.ProjectProgress> ProjectProgress { get; set; }
        public virtual IDbSet<Prm.System.Substance> Substance { get; set; }
        public virtual IDbSet<Prm.Project.ProjectInfo> ProjectInfo { get; set; }
        public virtual IDbSet<Prm.Project.ProjectRoleInfo> ProjectRoleInfo { get; set; }
        public virtual IDbSet<Prm.System.Product> Product { get; set; }
        public virtual IDbSet<Prm.Project.ProjectTeam> ProjectTeam { get; set; }
        public virtual IDbSet<Prm.Project.TeamComment> TeamComment { get; set; }
        public virtual IDbSet<Prm.System.DocumentType> DocumentType { get; set; }
        public virtual IDbSet<Prm.Project.ProjectDocmeut> ProjectDocmeut { get; set; }
        public virtual IDbSet<Prm.Project.ProjectDocmeutVersion> ProjectDocmeutVersion { get; set; }
        public virtual IDbSet<Prm.Project.ProjectDocType> ProjectDocType { get; set; }

        public virtual IDbSet<Prm.Project.Topic> Topic { get; set; }
        public virtual IDbSet<Prm.Project.Reply> Reply { get; set; }

        public virtual IDbSet<Prm.System.Laboratory> Laboratory { get; set; }
        public virtual IDbSet<Prm.System.RdCenter> RdCenter { get; set; }

        public virtual IDbSet<Prm.Authorization.ProjectRoleFunctionActions> ProjectRoleFunctionActions { get; set; }
        public virtual IDbSet<Prm.Authorization.ProjectRoleDocmentActions> ProjectRoleDocmentActions { get; set; }
        public virtual IDbSet<Prm.Authorization.SystemRoleFunctionActions> SystemRoleFunctionActions { get; set; }
        public virtual IDbSet<Prm.Authorization.SystemRoleDocmentActions> SystemRoleDocmentActions { get; set; }

        public virtual IDbSet<Prm.System.OperationLog> OperationLog { get; set; }
        

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Gantt.Dependency>().HasRequired(x => x.FromTask).WithMany(x => x.Predecessors).HasForeignKey(x => x.FromIdRaw).WillCascadeOnDelete(false);
            modelBuilder.Entity<Gantt.Dependency>().HasRequired(x => x.ToTask).WithMany(x => x.Successors).HasForeignKey(x => x.ToIdRaw).WillCascadeOnDelete(false);
            base.OnModelCreating(modelBuilder);
        }



        /* Define an IDbSet for each entity of the application */

        public virtual IDbSet<BinaryObject> BinaryObjects { get; set; }

        /* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
         * But it may cause problems when working Migrate.exe of EF. ABP works either way.         * 
         */
        public AbpZeroTemplateDbContext()
            : base("Default")
        {

        }

        /* This constructor is used by ABP to pass connection string defined in AbpZeroTemplateDataModule.PreInitialize.
         * Notice that, actually you will not directly create an instance of AbpZeroTemplateDbContext since ABP automatically handles it.
         */
        public AbpZeroTemplateDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {

        }

        /* This constructor is used in tests to pass a fake/mock connection.
         */
        public AbpZeroTemplateDbContext(DbConnection dbConnection)
            : base(dbConnection, true)
        {

        }
    }
}
